// ignore_for_file: prefer_const_constructors, avoid_print, prefer_interpolation_to_compose_strings

import 'package:flutter/material.dart';
import 'package:get/get.dart';

/*
  ValueBuilder 更像个小型的 StatefulWidget
  通过 updateFn 来更新数据
*/

class ValueBuilderSta extends StatelessWidget {
  const ValueBuilderSta({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          "ValueBuilder"
        ),
        
      ),
      body: Column(
        children: <Widget>[
          Center(
            child: ValueBuilder<int?>(
              initialValue: 10,
              builder: (value, updateFn) {
                return Column(
                  children: <Widget>[
                    Text("ValueBuilder<int?>()",),
                    SizedBox(height: 20,),
                    Text("count -> " + value.toString()),
                    SizedBox(height: 20,),
                    ElevatedButton(onPressed: () => updateFn( value ! + 1), child: Text("ValueBuilder -> add"))
                  ],
                );
              },
              onUpdate: (value) => print("Value updated: $value"),
              onDispose: () => print("Widget unmounted"),
            ),
          )
        ],
      ),
    );
  }
}